package com.ty.admin.controller;

import java.util.Arrays;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ty.skysystem.entity.GoodsEntity;
import com.ty.skysystem.service.GoodsService;
import com.ty.common.utils.PageUtils;
import com.ty.common.utils.R;

/**
 * 货物单信息表: 用于存放和管理货物单信息 字段名: carriers_id => 对应表: carriers
 *
 * @author tianyuzhu
 * @email 1659770218@QQ.COM
 * @date 2020-12-11 15:59:18
 */
@RestController
@RequestMapping("goods")
public class GoodsController {
  @Autowired private GoodsService goodsService;

  /** 列表 */
  @RequestMapping("/list")
  public R list(@RequestParam Map<String, Object> params) {
    PageUtils page = goodsService.queryPage(params);

    return R.ok().put(page);
  }

  /** 信息 */
  @RequestMapping("/info/{goodsId}")
  public R info(@PathVariable("goodsId") Long goodsId) {
    GoodsEntity goods = goodsService.getById(goodsId);

    return R.ok().put(goods);
  }

  /** 保存 */
  @RequestMapping("/save")
  public R save(@RequestBody GoodsEntity goods) {
    goodsService.save(goods);

    return R.ok();
  }

  /** 修改 */
  @RequestMapping("/update")
  public R update(@RequestBody GoodsEntity goods) {
    goodsService.updateById(goods);

    return R.ok();
  }

  /** 删除 */
  @RequestMapping("/delete")
  public R delete(@RequestBody Long[] goodsIds) {
    goodsService.removeByIds(Arrays.asList(goodsIds));

    return R.ok();
  }
}
